<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
</head>

<body>

    <h2>JavaScript 对象</h2>

    <p id="demo"></p>
    <p id="demo2"></p>
    <p id="demo3"></p>

    <script>
        function Person(first, last, age, eye) {
            this.firstName = first;
            this.lastName = last;
            this.age = age;
            this.eyeColor = eye;
        }

        var myFather = new Person("John", "Doe", 50, "blue");
        var myMother = new Person("Sally", "Rally", 48, "green");

        document.getElementById("demo").innerHTML =
            "我的父亲年龄是 " + myFather.age + "。我的母亲年龄是 " + myMother.age; 

        // 添加属性和方法
        Person.prototype.nationality = "English";
        document.getElementById("demo2").innerHTML =
             "母亲的国籍是：" + myFather.nationality + "<br/> 父亲的国籍是：" + myMother.nationality;

        Person.prototype.fullName = function(){
            return this.lastName + " " + this.firstName;
        };
        document.getElementById("demo3").innerHTML =
             "母亲的名字是：" + myFather.fullName() + "<br/> 父亲的名字是：" + myMother.fullName();
    </script>


</body>

</html>